package cc.atliberty.oa.controller;

import cc.atliberty.oa.pojo.Dept;
import cc.atliberty.oa.service.DeptService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
@WebServlet("/dept/detail")
public class DeptDetailServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String deptno = request.getParameter("deptno");
        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        DeptService deptService = context.getBean("deptService", DeptService.class);
        Dept dept = deptService.deptDetail(deptno);
        request.setAttribute("dept",dept );
        request.getRequestDispatcher("/" + request.getParameter("f") + ".jsp").forward(request,response);
    }
}
